package com.tzh.plugin.utils;

import com.github.pagehelper.Page;
import org.mybatis.generator.api.dom.java.CompilationUnit;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;

import java.util.HashMap;
import java.util.Map;

public class GenerateUtils {


    static final Map<String, String> apiDesc = new HashMap<String, String>();

    static {
        apiDesc.put("query", "列表查询");
        apiDesc.put("add", "添加");
        apiDesc.put("del", "条件删除");
        apiDesc.put("update", "根据Id更新");
        apiDesc.put("delById", "根据Id删除");
        apiDesc.put("selectById", "详情");
    }

    /**
     * 引包
     *
     * @param cls
     * @param dtoPkg
     * @param className
     * @param classType
     * @param dtoData
     */
    public static void setImports(CompilationUnit cls, String dtoPkg, String className, String classType, Map<String, FullyQualifiedJavaType> dtoData) {

        String queryDto = dtoPkg + ".query.Query" + className + "Dto";
        String addDto = dtoPkg + ".add.Add" + className + "Dto";
        String listDto = dtoPkg + ".list.List" + className + "Dto";
        String delDto = dtoPkg + ".del.Del" + className + "Dto";
        String utDto = dtoPkg + ".modify.Mod" + className + "Dto";
        String detailDto = dtoPkg + ".detail.Detail" + className + "Dto";
        FullyQualifiedJavaType listType = new FullyQualifiedJavaType(listDto);
        cls.addImportedType(listType);
        cls.addImportedType(new FullyQualifiedJavaType(queryDto));
        cls.addImportedType(new FullyQualifiedJavaType(addDto));
        cls.addImportedType(new FullyQualifiedJavaType(delDto));
        cls.addImportedType(new FullyQualifiedJavaType(utDto));
        cls.addImportedType(new FullyQualifiedJavaType(Page.class.getName()));

        cls.addImportedType(new FullyQualifiedJavaType(detailDto));
        cls.addImportedType(new FullyQualifiedJavaType(classType));

        //获取对应的类型
        dtoData.put("list", listType);
        dtoData.put("listRet", new FullyQualifiedJavaType("Page<" + listType.getShortName() + ">"));
        dtoData.put("query", new FullyQualifiedJavaType(queryDto));
        dtoData.put("add", new FullyQualifiedJavaType(addDto));
        dtoData.put("del", new FullyQualifiedJavaType(delDto));
        dtoData.put("model", new FullyQualifiedJavaType(classType));
        dtoData.put("int", new FullyQualifiedJavaType(Integer.class.getName()));
        dtoData.put("update", new FullyQualifiedJavaType(utDto));
        dtoData.put("detail", new FullyQualifiedJavaType(detailDto));
    }

}
